﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bitcoin.Net;
using NUnit.Framework;

namespace Bitcoin.Test.Net
{
    [TestFixture]
    public class NetAddressTest
    {
        [Test]
        [TestCase("1.2.3.4", true, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 1, 2, 3, 4 })]
        [TestCase("102:304:506:708:90a:b0c:d0e:f10", false, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 })]
        [TestCase("2001:db8::1:0:0:1", false, new byte[] { 0x20, 1, 0xd, 0xb8, 
            0, 0, 0, 0, 
            0, 1, 0, 0, 
            0, 0, 0, 1 })]
        [TestCase("2001:db8:0:1:1:1:1:1", false, new byte[] { 0x20, 1, 0xd, 0xb8, 
            0, 0, 0, 1, 
            0, 1, 0, 1, 
            0, 1, 0, 1 })]
        public void TestParse(string s, bool isIPv4, byte[] bytes)
        {
            var address = NetAddress.Parse(s);
            var actual = address.Bytes;
            Assert.AreEqual(bytes, actual);
            Assert.AreEqual(isIPv4, address.IsIPv4);
        }

        [Test]
        [TestCase("1.2.3.4", true, new byte[] { 1, 2, 3, 4 })]
        [TestCase("102:304:506:708:90a:b0c:d0e:f10", false, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 })]
        [TestCase("2001:db8::1:0:0:1",    false, new byte[] { 0x20, 1, 0xd, 0xb8, 
            0, 0, 0, 0, 
            0, 1, 0, 0, 
            0, 0, 0, 1 })]
        [TestCase("2001:db8:0:1:1:1:1:1", false, new byte[] { 0x20, 1, 0xd, 0xb8, 
            0, 0, 0, 1, 
            0, 1, 0, 1, 
            0, 1, 0, 1 })]
        public void TestString(string s, bool isIPv4, byte[] bytes)
        {
            var address = new NetAddress(bytes);
            var actual = address.ToString();
            Assert.AreEqual(s, actual);
        }

    }
}
